<#include "/common/h-ui-base-css.html">
<#include "/common/h-ui-base-js.html">
<#include "/common/validation-js.html">
<script type="text/javascript" src="/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-equipment-add">
        <table class="table table-border table-bordered table-bg">
            <thead>
                <tr class="text-c">
                    <th>设备名称</th>
                    <th>设备分类</th>
                    <th>设备价格</th>
                    <th>租赁单位</th>
                </tr>
            </thead>
            <tbody>
                <tr class="text-c">
                    <td>
                        <div class="formControls">
                             <input type="text" class="input-text" value="${entity.equipName!}" placeholder="" id="equipName" name="equipName">
                        </div>
                    </td>
                    <td>
                        <span class="formControls select-box inline" style="width: 98%;height: 31px">
                            <select class="select good_source" style="width: 98%;height: 100%" id="equipType" name="equipType" >
                                <option value="">--请选择设备类型--</option>
                            </select>
                        </span>
                    </td>
                    <td>
                        <div class="formControls">
                            <input type="text" class="input-text" value="${entity.equipPurchaseMoney!}" placeholder="" id="equipPurchaseMoney" name="equipPurchaseMoney">
                        </div>
                    </td>
                    <td>
                        <div class="formControls">
                            <input type="text" class="input-text" value="${entity.equipRentUnit!}" placeholder="" id="equipRentUnit" name="equipRentUnit">
                        </div>
                    </td>
                </tr>
            </tbody>
            <thead>
            <tr class="text-c">
                <th>设备厂商</th>
                <th>采购日期</th>
                <th>资产归属单位</th>
                <th>使用位置</th>
            </tr>
            </thead>
            <tbody>
                <tr class="text-c">
                    <td>
                        <div class="formControls">
                            <input type="text" class="input-text" value="${entity.equipFactory!}" placeholder="" id="equipFactory" name="equipFactory">
                        </div>
                    </td>
                    <td>
                        <div class="formControls">
                                <input type="text" name="equipPurchaseTime" id="equipPurchaseTime" class="Wdate input-text" onclick="WdatePicker()" >
                        </div>
                    </td>
                    <td>
                        <span class="formControls select-box inline" style="width: 98%;height: 31px">
                            <select class="select good_source" style="width: 98%;height: 100%" id="equipBelongTo" name="equipBelongTo" >
                                <option value="">--请选择资产归属单位类型--</option>
                            </select>
                        </span>
                        <div class="formControls">
                            <#--<input type="text" class="input-text" value="${entity.equipBelongTo!}" placeholder="" id="equipBelongTo" name="equipBelongTo">-->
                        </div>
                    </td>
                    <td>
                        <div class="formControls">
                            <input type="text" class="input-text" value="${entity.equipUsedLocation!}" placeholder="" id="equipUsedLocation" name="equipUsedLocation">
                        </div>
                    </td>
                </tr>
            </tbody>
            <thead>
            <tr class="text-c">
                <th>库房保存位置</th>
                <th>设备状态</th>
                <th>租赁状态</th>
                <th>技术文件</th>
            </tr>
            </thead>
            <tbody>
            <tr class="text-c">
                <td>
                    <div class="formControls">
                        <input type="text" class="input-text" value="${entity.equipLocaltion!}" placeholder="" id="equipLocaltion" name="equipLocaltion">
                    </div>
                </td>
                <td>
                    <div class="formControls">
                        <input type="text" class="input-text" value="${entity.equipState!}" placeholder="" id="equipState" name="equipState">
                    </div>
                </td>
                <td>
                    <span class="formControls select-box inline" style="width: 98%;height: 31px">
                            <select class="select good_source" style="width: 98%;height: 100%" id="equipRentState" name="equipRentState" >
                                <option value="">--请选择租赁状态--</option>
                            </select>
                    </span>
                    <#--<div class="formControls">-->
                        <#--<input type="text" class="input-text" value="${entity.equipRentState!}" placeholder="" id="equipRentState" name="equipRentState">-->
                    <#--</div>-->
                </td>
                 <td>
                    <div class="formControls">
                        <input type="text" class="input-text" value="${entity.equipTechnology!}" placeholder="" id="equipTechnology" name="equipTechnology">
                    </div>
                </td>

            </tr>
            </tbody>
            <thead>
                <tr class="text-c">
                    <th colspan="4">设备规格</th>
                </tr>
            </thead>
            <tbody>
                <td colspan="4">
                    <div class="formControls">
                        <textarea name="equipSpecifications" id="equipSpecifications" cols="4" rows="" class="textarea"  placeholder="说点什么...最少输入10个字符"></textarea>
                        <p class="textarea-numberbar"><em class="textarea-length">0</em>/200</p>
                    </div>
                </td>
            </tbody>
        </table>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript">

    $(function(){
        var id = ${entity.id?default(-1)?c}
        init();
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        $("#form-equipment-add").validate({
            rules:{
                equipName:{
                    required:true,
                    minlength:2,
                    maxlength:16
                },
                equipType:{
                    required:true,
                    minlength:1,
                    maxlength:16
                },
                equipSpecifications:{
                    required:true,
                    minlength:2
                },
                equipPurchaseTime:{
                    required:true
                },
                equipPurchaseMoney:{
                    required:true,
                    number:true
                },
                equipBelongTo:{
                    required:true,
                },
                equipRentState:{
                    required:true,
                }

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                $(form).ajaxSubmit({
                    type: 'post',
                    url: "/equipment-save/"+id ,
                    data :$("form-equipment-add").serialize(),
                    async:false,
                    success: function(data){
                        layer.msg('添加成功!',{icon:1,time:1000});
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg('error!',{icon:1,time:1000});
                    }
                });
                var index = parent.layer.getFrameIndex(window.name);
                var handler = '/equip-list-json/0/20';
                parent.$('#equipment_table').datagrid('options').url = handler;
                parent.$('#equipment_table').datagrid('reload');
                parent.layer.close(index);
            }
        });
    });
</script>

<script type="text/javascript">
    function  init() {
        ///需要整合
        //
        $.ajax({
            url : '/constants/equipment-types',
            type : 'get',
            async : false,
            success : function(data){
                var types = data;
                var selEquipType = $('#equipType');
                for(var i=0;i<types.length;i++){
                    selEquipType.append("<option value='"+types[i].key+"'>"+types[i].value+"</option>");
                }
            }
        })
        //
        $.ajax({
            url : '/constants/equipment-belong',
            type : 'get',
            async : false,
            success : function(data){
                var types = data;
                var selEquipBelongTo = $('#equipBelongTo');
                for(var i=0;i<types.length;i++){
                    selEquipBelongTo.append("<option value='"+types[i].key+"'>"+types[i].value+"</option>");
                }
            }
        });
        //
        $.ajax({
            url : '/constants/equipment-rent-state',
            type : 'get',
            async : false,
            success : function(data){
                var types = data;
                var equipRentState = $('#equipRentState');
                for(var i=0;i<types.length;i++){
                    equipRentState.append("<option value='"+types[i].key+"'>"+types[i].value+"</option>");
                }
            }
        });
        //初始化
        var equipType = '${entity.equipType!}';
        if(equipType!=''){
            $('#equipType').find('option[value='+equipType+']').attr("selected",true);
        }
        var equipBelongTo = '${entity.equipBelongTo!}';
        if(equipBelongTo!=''){
            console.log('aa')
            $('#equipBelongTo').find('option[value='+equipBelongTo+']').attr("selected",true);
        }
        var equipRentState = '${entity.equipRentState!}';
        if(equipRentState!=''){
            $('#equipRentState').find('option[value='+equipRentState+']').attr("selected",true);
        }
        var equipSpecifications = '${entity.equipSpecifications!}';
        if(equipSpecifications!=''){
            $('#equipSpecifications').val(equipSpecifications)
        }
        var equipPurchaseTime = '${entity.equipPurchaseTime!}';
        if(equipPurchaseTime!=''){
            $('#equipPurchaseTime').val(equipPurchaseTime)
        }



    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
